home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- opaste - Paste an image into the overlay or pup planes.
-
- Tim Heidmann, Silicon Graphics
- December 7, 1992
- */
- #include <gl.h>
- #include <device.h>
- #include <gl/image.h>
- #include <stdio.h>
-
- long mainMenu;
- int frameDetached, iconified, usePupPlanes, autoPop, canOverlay;
- long xorg, yorg, xsize, ysize;
- int useColor[][3] = {
- 0, 0, 0,
- 0, 0, 0,
- 128, 128, 128,
- 255, 255, 255
- };
-
-
- main(int argc, char *argv[]) {
- unsigned short *buf, *p;
- IMAGE *f;
- int i, irow, icol, done, wid;
- long xorg2, yorg2;
- float update_rate = 5.0;
- short dev, val;
-
- /* Parse arguments */
- if (argc != 2) {
- fprintf(stderr, "usage: %s <image file>\n", argv[0]);
- exit(1);
- }
- if ((f = iopen(argv[1], "r")) == NULL) {
- fprintf(stderr, "Can't open image file %s\n", argv[1]);
- exit(1);
- }
- if (f->zsize != 1) {
- fprintf(stderr,
- "Warning: %s is not a single channel image.\n",
- argv[1]);
- }
-
- /* Open a window and get its location */
- prefsize(xsize = f->xsize, ysize = f->ysize);
- iconsize(100, 100);
- wid = winopen(argv[1]);
- getorigin(&xorg, &yorg);
-
- if (canOverlay) overlay(2);
- gconfig();
- color(BLACK);
- clear();
- frameDetached = FALSE;
- iconified = FALSE;
- autoPop = FALSE;
- canOverlay = getgdesc(GD_BITS_OVER_SNG_CMODE) > 0;
- usePupPlanes = !canOverlay;
-
- mainMenu = newpup();
- MakeMenu();
-
- /* Read the image to be displayed. Quantize if not a colormap image. */
- buf = (unsigned short *) malloc(f->xsize * f->ysize * sizeof(short));
- for (irow = 0, p = buf; irow < f->ysize; irow++) {
- getrow(f, p, irow, 0);
- if (f->colormap != CM_SCREEN)
- for (icol = 0; icol < f->xsize; icol++, p++) *p >>= 6;
- else
- p += f->xsize;
- }
- iclose(f);
-
- /* All these devices are needed to manage iconifying and closing right. */
- qdevice(DEPTHCHANGE);
- qdevice(REDRAW);
- qdevice(REDRAWICONIC);
- qdevice(WINSHUT);
- qdevice(WINQUIT);
- qdevice(WINFREEZE);
- qdevice(WINTHAW);
- qdevice(ESCKEY);
- qdevice(RIGHTMOUSE);
- qdevice(TIMER1);
- noise(TIMER1, (int)(update_rate * getgdesc(GD_TIMERHZ)));
-
- qenter(TIMER1, 0);
- for (done = FALSE; !done; ) {
- switch (dev = qread(&val)) {
- case WINFREEZE:
- case WINTHAW:
- break;
-
- case ESCKEY:
- case WINSHUT:
- case WINQUIT:
- done = TRUE; break;
-
- case REDRAW:
- iconified = FALSE;
- reshapeviewport();
- if (!frameDetached) {
- getorigin(&xorg2, &yorg2);
- if (xorg2 != xorg || yorg2 != yorg) {
- ClearRect();
- xorg = xorg2; yorg = yorg2;
- }
- }
- color(BLACK);
- clear();
- qenter(TIMER1, 0);
- break;
-
- case REDRAWICONIC:
- iconified = TRUE;
- color(BLACK);
- clear();
- if (!frameDetached) ClearRect();
- break;
-
- case RIGHTMOUSE:
- if (!val) break;
- switch (dopup(mainMenu)) {
- case 1: /* Hide/Show window frame */
- if (frameDetached) {
- prefposition(xorg, xorg+xsize-1, yorg, yorg+ysize-1);
- winconstraints();
- winpop();
- frameDetached = FALSE;
- } else {
- winconstraints();
- frameDetached = TRUE;
- }
- MakeMenu();
- break;
- case 2: /* Toggle bitplanes - PopUp/Overlay */
- ClearRect();
- usePupPlanes = !usePupPlanes;
- qenter(TIMER1, 0); /* Schedule redraw */
- MakeMenu();
- break;
- case 3: /* Toggle automatic pop window to front */
- autoPop = !autoPop;
- MakeMenu();
- break;
- case 99: /* Exit */
- done = TRUE;
- break;
- default:
- break;
- }
- break;
-
- case TIMER1:
- if (autoPop) winpop();
- case DEPTHCHANGE:
- if (iconified && !frameDetached) break;
- drawmode(usePupPlanes ? PUPDRAW : OVERDRAW);
- fullscrn();
- for (i=1; i<4; i++)
- mapcolor(i, useColor[i][0], useColor[i][1], useColor[i][2]);
- rectwrite(xorg, yorg, xorg+xsize-1, yorg+ysize-1, buf);
- endfullscrn();
- drawmode(NORMALDRAW);
- break;
-
- default:
- break;
- }
- }
-
- ClearRect();
- }
-
- MakeMenu() {
- freepup(mainMenu);
- mainMenu = defpup( "Overlay Paste%t");
- addtopup(mainMenu, frameDetached ? "Attach Frame%x1" : "Detach Frame%x1");
- if (canOverlay)
- addtopup(mainMenu, usePupPlanes ? "Use Overlay%x2" : "Use Popup%x2");
- addtopup(mainMenu, autoPop ? "Don't Auto Pop%x3%l" : "Auto Pop%l%x3");
- addtopup(mainMenu, "Quit %x99");
- }
-
- ClearRect() {
- drawmode(usePupPlanes ? PUPDRAW : OVERDRAW);
- fullscrn();
- color(0);
- rectfi(xorg, yorg, xorg+xsize-1, yorg+ysize-1);
- endfullscrn();
- drawmode(NORMALDRAW);
- }
-